package cn.edu.hit.education.labelprovider;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;

import cn.edu.hit.education.model.CollegeNode;
import cn.edu.hit.education.model.Node;
import cn.edu.hit.education.model.OrganizationNode;
import cn.edu.hit.education.model.SpecialtyNode;
import cn.edu.hit.education.model.UniversityNode;
import educationschedule.Activator;

public class DepartmentLabelProvider implements ILabelProvider {

	private Map<ImageDescriptor, Image> imageCache = new HashMap<ImageDescriptor, Image>(
			20);

	@Override
	public Image getImage(Object element) {
		ImageDescriptor descriptor = null;
		// obtain the cached image corresponding to the descriptor
		if (element instanceof OrganizationNode) {
			descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
			Activator.PLUGIN_ID, "icons/process.png");
		} else if (element instanceof UniversityNode) {
			descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
			Activator.PLUGIN_ID, "icons/process.png");
		} else if (element instanceof CollegeNode) {
			descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
			Activator.PLUGIN_ID, "icons/property.png");
		} else if (element instanceof SpecialtyNode) {
			descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
			Activator.PLUGIN_ID, "icons/course.png");
		}

		Image image = (Image) imageCache.get(descriptor);
		if (image == null) {
			image = descriptor.createImage();
			imageCache.put(descriptor, image);
		}
		return image;
	}

	@Override
	public String getText(Object element) {
		String text = "";
		text = ((Node)element).getName();
		return text;
	}

	@Override
	public void addListener(ILabelProviderListener listener) {
		// TODO Auto-generated method stub
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
	}

	@Override
	public boolean isLabelProperty(Object element, String property) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void removeListener(ILabelProviderListener listener) {
		// TODO Auto-generated method stub
	}

	protected RuntimeException unknownElement(Object element) {
		return new RuntimeException("Unknown type of element in tree of type "
				+ element.getClass().getName());
	}

}
